import { prisma } from "@/lib/prisma"
import { Metadata } from "next"
import { InventoryReport } from "@/components/reports/inventory-report"

export const metadata: Metadata = {
  title: "库存统计 - 商场销售系统",
  description: "库存统计页面",
}

export default async function InventoryReportPage() {
  // 获取库存数据
  const products = await prisma.product.findMany({
    orderBy: {
      createdAt: 'desc',
    },
  })

  // 计算总库存和总商品数量
  const totalStock = products.reduce((sum, product) => sum + product.stock, 0)
  const totalProducts = products.length

  return (
    <div className="space-y-4 p-8 bg-gray-50">
      <h1 className="text-2xl font-bold text-gray-900">库存统计</h1>
      <div className="bg-white p-6 rounded-lg shadow-lg border border-gray-200">
        <h2 className="text-xl text-gray-800 mb-4">统计信息</h2>
        <div className="flex justify-between">
          <div className="text-lg text-gray-700">总库存:</div>
          <div className="text-2xl font-semibold text-green-600">{totalStock}</div>
        </div>
        <div className="flex justify-between mt-2">
          <div className="text-lg text-gray-700">总商品数量:</div>
          <div className="text-2xl font-semibold text-blue-600">{totalProducts}</div>
        </div>
      </div>
      <div className="bg-white p-4 rounded shadow mt-4">
        <InventoryReport products={products} />
      </div>
    </div>
  )
} 